<template>
	<view class="home-main">
		<!-- 搜索 -->
		<view class="home-search" @click="gotoPath('/pages/searchPage/searchPage')">
			<view class="home-search-box">
				请输入商品名称
			</view>
		</view>

		<!-- 轮播 -->
		<view class="home-banner">
			<view class="home-banner-box">
				<image src="https://static.haiqigame.com/uploads/20250820/a23c0f75b86a838f5c1d8dae35138d5f.png"
					mode="widthFix"></image>
			</view>
		</view>

		<!-- 通知 -->
		<view class="home-tips">
			<uni-notice-bar show-icon scrollable
				text="欢迎各位老板来到捌贰捌电竞，未成年禁止在平台下单，有疑问随时联系客服（24小时）" />
		</view>

		<!-- 余额 -->
		<view class="home-pir">
			<view class="home-pir-box">
				<view class="pir-tit">
					余额：0.00
				</view>
				<view class="btn" @click="gotoPath('/pages/walletDetail/walletDetail')">
					查看明细
				</view>
			</view>
		</view>

		<!-- 分类 -->
		<view class="home-classify">
			<view class="home-classify-box">
				<view class="classify-item" v-for="item in categoryList" :key="item.id">
					<view class="classify-image">
						<image :src="item.images"
							mode="widthFix"></image>
					</view>
					<view class="classify-tit">
						{{item.name}}
					</view>
				</view>
			</view>
		</view>

		<!-- 游戏列表 -->
		<view class="home-gameShopping">
			<view class="gameList">
				<view class="gameItem" v-for="item in productList" :key="item.id" @click="gotoPath(`/pages/gameInfo/gameInfo?id=${item.id}`)">
					<view class="gameImage">
						<image :src="item.cover_image"
							mode="widthFix"></image>
					</view>

					<view class="game-tit">
						{{item.name}}
					</view>

					<view class="game-option">
						<view class="game-xl">
							销量 {{item.total_orders}}
						</view>
						<view class="game-liulan">
							浏览 60362
						</view>
					</view>

					<view class="game-pir">
						<view class="pir">
							<text style="font-size: 10px;">￥</text>{{item.price}}
						</view>
						<view class="yj-pir">
							￥{{item.original_price}}
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getCategoryList,
		getProductList
	} from '@/api/shop/shop.js'
	export default {
		data() {
			return {
				productForm:{
					game_id:"",
					category_id:"",
					keyword:"",
					page:1,
					pageSize:20
				},
				productList:[],
				categoryList:[]
			}
		},
		onLoad() {
			this.getCategoryListData()
			this.getProductListData()
		},
		methods: {
			// 获取商品分类
			async getCategoryListData(){
				try{
					const res = await getCategoryList({})
					this.categoryList = res.data.category;
				}catch(error){
					throw Error(error)
				}
			},
			
			// 获取商品列表
			async getProductListData(){
				try{
					const res = await getProductList(this.productForm)
					this.productList = res.data.product;
				}catch(error){
					throw Error(error)
				}
			},
			gotoPath(url) {
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.home-main {
		.home-search {
			box-sizing: border-box;
			padding: 20rpx;

			.home-search-box {
				box-sizing: border-box;
				height: 70rpx;
				background-color: #fff;
				border-radius: 16rpx;
				line-height: 70rpx;
				text-align: center;
				font-size: 24rpx;
				color: #999;
			}
		}

		.home-banner {
			box-sizing: border-box;
			padding: 20rpx;
			padding-top: 0px;

			.home-banner-box {
				height: 400rpx;
				background-color: #999;
				overflow: hidden;
				border-radius: 16rpx;
			}
		}

		.home-tips {
			box-sizing: border-box;
			padding: 0px 20rpx;
		}

		.home-pir {
			box-sizing: border-box;
			padding: 20rpx;
			padding-top: 0px;

			.home-pir-box {
				background-color: #fff;
				box-sizing: border-box;
				padding: 20rpx 30rpx;
				border-radius: 16rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.pir-tit {
					font-size: 32rpx;
					font-weight: 700;
				}

				.btn {
					width: 160rpx;
					height: 60rpx;
					background-color: red;
					color: #fff;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 24rpx;
					border-radius: 120rpx;
				}
			}
		}

		.home-classify {
			padding: 0px 20rpx;

			.home-classify-box {
				box-sizing: border-box;
				padding: 20rpx;
				background-color: #fff;
				display: flex;
				gap: 20px;
				border-radius: 16rpx;
				overflow: hidden;

				.classify-item {
					.classify-image {
						width: 90rpx;
						height: 90rpx;
						font-size: 0px;
						margin-bottom: 10rpx;
						border-radius: 4px;
						overflow: hidden;
					}

					.classify-tit {
						text-align: center;
						font-size: 24rpx;
					}
				}
			}

		}

		.home-gameShopping {
			box-sizing: border-box;
			padding: 20rpx;
			padding-right: 10rpx;

			.gameList {
				display: flex;
				flex-wrap: wrap;
				gap: 10px;

				.gameItem {
					width: 48%;
					background-color: #fff;
					border-radius: 16rpx;
					overflow: hidden;

					.gameImage {
						width: 100%;
						height: 350rpx;
						font-size: 0px;
					}

					.game-tit {
						font-size: 26rpx;
						box-sizing: border-box;
						padding: 0rpx 20rpx;
						margin: 10rpx 0px;
						
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
						text-overflow: ellipsis;
						
						/* 兼容性处理 */
						line-clamp: 2;
						box-orient: vertical;
						
						/* 文本换行设置 */
						word-wrap: break-word;
						word-break: break-word;
					}

					.game-option {
						display: flex;
						align-items: center;
						justify-content: space-between;
						box-sizing: border-box;
						padding: 0px 20rpx;
						font-size: 22rpx;
						color: #999;
					}

					.game-pir {
						display: flex;
						align-items: center;
						justify-content: space-between;
						box-sizing: border-box;
						padding: 10rpx 20rpx;
						font-size: 30rpx;
						padding-bottom: 20rpx;

						.pir {
							color: red;
						}

						.yj-pir {
							color: #999;
							font-size: 24rpx;
							text-decoration: line-through;
						}
					}
				}
			}
		}
	}
</style>